t2a19-leet-caleb.html



  • Ask chatGPT for a beginner friendly javascript leet code question.


  • record the question on this webpage


  • write your code to solve the problem within pre tags


    1. show your prompt here


    2. LeetCode Question: FizzBuzz(x) "create a function that takes a parameter as a variable, prints numbers up to that parameter set, if divisible by 3 print fizz if divisible by 5 print buzz if divisible by 3 AND 5 print fizzbuzz (15, 30, 45, 60"


    3. show the leet question here


    4. within pre tags show your version of the leet answer without looking up the actual answer.
    5. 	button id="myButton"/button
      	span id="myOutput"/span
      	
      		// variables
      		const span = document.getElementById('myOutput');
      		const button = document.getElementById('myButton');
      		// working stuff
      		function fizzbuzz(n) {
      			
      			let end = "";
      			
      			for (let i = 1; i <= n; i++) {
      				if (i % 15 === 0) {
      					end += "fizzbuzz";
      				} else if (i % 3 === 0) {
      					end += "fizz";
      				} else if (i % 5 === 0) {
      					end += "buzz";
      				} else {
      					end += i + "";
      				}
      			}
      			
      			span.innerHTML = end;
      		}
      		button.addEventListener('click', () => fizzbuzz(100));
      	
      


    6. put the chatgpt working code here (sensibly it does not need several tags that are not used)
    7. FizzBuzz Generator

      Click "Generate Sequence" to run FizzBuzz.